id/email
password
forgot password | create account
about | help | prefs
ReadingBatcode reading practice

 

 

Lambda IntroIntListLambda1

prev  |  next  |  chance

val tripleIt4: (Int) -> Int = { i: Int -> i * 3 }

val quadIt4: (Int) -> Int = { i: Int -> i * 4 }

fun doubleIt4(i: Int): Int = i * 2

fun func4(i: Int, funcs: List<(Int) -> Int>): List<Int> =
  buildList {
    funcs.forEach { func: (Int) -> Int ->
      add(func((i)))
    }
  }

Function Call  Return Value
func4(4, listOf(tripleIt4))
func4(5, listOf(tripleIt4, tripleIt4))
func4(10, listOf(quadIt4, tripleIt4, tripleIt4))
func4(20, listOf(::doubleIt4, tripleIt4, ::doubleIt4))
func4(20, listOf({ i: Int -> i * 3 }, { i: Int -> i * 2 }))
func4(20, listOf({ i: Int -> i * 3 }, { it * 4 }))

Experiment with this code on Gitpod.io or as a Kotlin Playground

⬅ Back